package com.taiyuan.tongcheng.jsonparser;

import org.json.JSONException;
import org.json.JSONObject;

import com.taiyuan.tongcheng.bean.UserInfo;
import com.taiyuan.tongcheng.http.WebData;

public class TcJsParser {
	/**
	 *  获取基本数据
	 * @param json
	 * @return
	 */
    public static WebData  getWedataData(String json){
    	JSONObject jsonObj;
    	WebData webData=new WebData();
		try {
			jsonObj = new JSONObject(json);
			webData.setStatus(jsonObj.optInt("status", 1));
			webData.setMsg(jsonObj.optString("msg", ""));
			webData.setData(jsonObj.optString("data", ""));
		} catch (JSONException e) {
			e.printStackTrace();
		}
    	return webData;
    }
    
    public static UserInfo  getUserInfo(String json){
    	JSONObject jsonObj;
    	UserInfo info =new UserInfo();
    	try {
			jsonObj = new JSONObject(json);
			info.setAddressCount(jsonObj.optInt("addressCount", 0));
			info.setUid(jsonObj.optString("uid", ""));
			info.setMobile(jsonObj.optString("mobile",""));
			info.setName(jsonObj.optString("name", ""));
			info.setToken(jsonObj.optString("token", ""));
			info.setValidFlag(jsonObj.optInt("validFlag", 1));
			info.setHuiYueTimes(jsonObj.optInt("huiYueTimes", 0));
		} catch (JSONException e) {
			e.printStackTrace();
		}
    	return info;
    }
}
